.class public final Lcom/alipay/android/app/util/FileDownloader;
.super Ljava/lang/Object;


# instance fields
.field private fetch:Lcom/alipay/android/app/util/FileFetch;

.field private fileUrl:Ljava/lang/String;

.field private progressOutput:Lcom/alipay/android/app/util/FileDownloader$IDownloadProgress;

.field private savePath:Ljava/lang/String;

.field public showProgress:Z

.field private tmpPath:Ljava/lang/String;


# direct methods
.method public constructor <init>()V
    .locals 1

    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    const/4 v0, 0x0

    iput-boolean v0, p0, Lcom/alipay/android/app/util/FileDownloader;->showProgress:Z

    return-void
.end method

.method public constructor <init>(Z)V
    .locals 0

    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    iput-boolean p1, p0, Lcom/alipay/android/app/util/FileDownloader;->showProgress:Z

    return-void
.end method

.method static synthetic access$0(Lcom/alipay/android/app/util/FileDownloader;)Lcom/alipay/android/app/util/FileDownloader$IDownloadProgress;
    .locals 1

    iget-object v0, p0, Lcom/alipay/android/app/util/FileDownloader;->progressOutput:Lcom/alipay/android/app/util/FileDownloader$IDownloadProgress;

    return-object v0
.end method

.method static synthetic access$1(Lcom/alipay/android/app/util/FileDownloader;)Lcom/alipay/android/app/util/FileFetch;
    .locals 1

    iget-object v0, p0, Lcom/alipay/android/app/util/FileDownloader;->fetch:Lcom/alipay/android/app/util/FileFetch;

    return-object v0
.end method

.method static synthetic access$2(Lcom/alipay/android/app/util/FileDownloader;)V
    .locals 0

    invoke-direct {p0}, Lcom/alipay/android/app/util/FileDownloader;->deleteFile()V

    return-void
.end method

.method static synthetic access$3(Lcom/alipay/android/app/util/FileDownloader;)Ljava/lang/String;
    .locals 1

    iget-object v0, p0, Lcom/alipay/android/app/util/FileDownloader;->fileUrl:Ljava/lang/String;

    return-object v0
.end method

.method static synthetic access$4(Lcom/alipay/android/app/util/FileDownloader;)Ljava/lang/String;
    .locals 1

    iget-object v0, p0, Lcom/alipay/android/app/util/FileDownloader;->savePath:Ljava/lang/String;

    return-object v0
.end method

.method static synthetic access$5(Lcom/alipay/android/app/util/FileDownloader;Lcom/alipay/android/app/util/FileFetch;)V
    .locals 0

    iput-object p1, p0, Lcom/alipay/android/app/util/FileDownloader;->fetch:Lcom/alipay/android/app/util/FileFetch;

    return-void
.end method

.method static synthetic access$6(Lcom/alipay/android/app/util/FileDownloader;)J
    .locals 2

    invoke-direct {p0}, Lcom/alipay/android/app/util/FileDownloader;->getFileSize()J

    move-result-wide v0

    return-wide v0
.end method

.method static synthetic access$7(Lcom/alipay/android/app/util/FileDownloader;)V
    .locals 0

    invoke-direct {p0}, Lcom/alipay/android/app/util/FileDownloader;->readTempFile()V

    return-void
.end method

.method private deleteFile()V
    .locals 2

    new-instance v0, Ljava/io/File;

    iget-object v1, p0, Lcom/alipay/android/app/util/FileDownloader;->savePath:Ljava/lang/String;

    invoke-direct {v0, v1}, Ljava/io/File;-><init>(Ljava/lang/String;)V

    invoke-virtual {v0}, Ljava/io/File;->exists()Z

    move-result v1

    if-eqz v1, :cond_0

    invoke-virtual {v0}, Ljava/io/File;->delete()Z

    :cond_0
    new-instance v0, Ljava/io/File;

    iget-object v1, p0, Lcom/alipay/android/app/util/FileDownloader;->tmpPath:Ljava/lang/String;

    invoke-direct {v0, v1}, Ljava/io/File;-><init>(Ljava/lang/String;)V

    invoke-virtual {v0}, Ljava/io/File;->exists()Z

    move-result v1

    if-eqz v1, :cond_1

    invoke-virtual {v0}, Ljava/io/File;->delete()Z

    :cond_1
    return-void
.end method

.method private getFileSize()J
    .locals 4

    const-wide/16 v0, -0x1

    :try_start_0
    iget-object v2, p0, Lcom/alipay/android/app/util/FileDownloader;->fileUrl:Ljava/lang/String;

    const/4 v3, 0x0

    invoke-static {v2, v3}, Lcom/alipay/android/app/util/FileDownloader;->getHttpEntity(Ljava/lang/String;Z)Lorg/apache/http/HttpEntity;

    move-result-object v2

    invoke-interface {v2}, Lorg/apache/http/HttpEntity;->getContentLength()J
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    move-result-wide v0

    :goto_0
    return-wide v0

    :catch_0
    move-exception v2

    invoke-virtual {v2}, Ljava/lang/Exception;->printStackTrace()V

    goto :goto_0
.end method

.method public static getHttpEntity(Ljava/lang/String;Z)Lorg/apache/http/HttpEntity;
    .locals 4

    :try_start_0
    new-instance v0, Lorg/apache/http/client/methods/HttpGet;

    invoke-direct {v0, p0}, Lorg/apache/http/client/methods/HttpGet;-><init>(Ljava/lang/String;)V

    new-instance v1, Lorg/apache/http/impl/client/DefaultHttpClient;

    invoke-direct {v1}, Lorg/apache/http/impl/client/DefaultHttpClient;-><init>()V

    if-eqz p1, :cond_0

    const-string v2, "Accept-Encoding"

    const-string v3, "gzip"

    invoke-virtual {v0, v2, v3}, Lorg/apache/http/client/methods/HttpGet;->addHeader(Ljava/lang/String;Ljava/lang/String;)V

    :cond_0
    invoke-interface {v1, v0}, Lorg/apache/http/client/HttpClient;->execute(Lorg/apache/http/client/methods/HttpUriRequest;)Lorg/apache/http/HttpResponse;

    move-result-object v0

    invoke-interface {v0}, Lorg/apache/http/HttpResponse;->getStatusLine()Lorg/apache/http/StatusLine;

    move-result-object v1

    invoke-interface {v1}, Lorg/apache/http/StatusLine;->getStatusCode()I

    move-result v1

    const/16 v2, 0xc8

    if-ne v1, v2, :cond_1

    invoke-interface {v0}, Lorg/apache/http/HttpResponse;->getEntity()Lorg/apache/http/HttpEntity;

    move-result-object v0

    :goto_0
    return-object v0

    :cond_1
    new-instance v0, Ljava/lang/Exception;

    new-instance v2, Ljava/lang/StringBuilder;

    const-string v3, "net work exception,ErrorCode :"

    invoke-direct {v2, v3}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v2, v1}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    invoke-direct {v0, v1}, Ljava/lang/Exception;-><init>(Ljava/lang/String;)V

    throw v0
    :try_end_0
    .catch Ljavax/net/ssl/SSLException; {:try_start_0 .. :try_end_0} :catch_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_1

    :catch_0
    move-exception v0

    invoke-virtual {v0}, Ljavax/net/ssl/SSLException;->printStackTrace()V

    :goto_1
    const/4 v0, 0x0

    goto :goto_0

    :catch_1
    move-exception v0

    invoke-virtual {v0}, Ljava/lang/Exception;->printStackTrace()V

    goto :goto_1
.end method

.method private readTempFile()V
    .locals 6

    const/4 v2, 0x0

    :try_start_0
    new-instance v3, Ljava/io/FileInputStream;

    iget-object v0, p0, Lcom/alipay/android/app/util/FileDownloader;->tmpPath:Ljava/lang/String;

    invoke-direct {v3, v0}, Ljava/io/FileInputStream;-><init>(Ljava/lang/String;)V
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    :try_start_1
    new-instance v1, Ljava/io/ObjectInputStream;

    invoke-direct {v1, v3}, Ljava/io/ObjectInputStream;-><init>(Ljava/io/InputStream;)V
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_1
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_7

    :try_start_2
    iget-object v0, p0, Lcom/alipay/android/app/util/FileDownloader;->fetch:Lcom/alipay/android/app/util/FileFetch;

    invoke-virtual {v1}, Ljava/io/ObjectInputStream;->readLong()J

    move-result-wide v4

    invoke-virtual {v0, v4, v5}, Lcom/alipay/android/app/util/FileFetch;->setFileStart(J)V

    iget-object v0, p0, Lcom/alipay/android/app/util/FileDownloader;->fetch:Lcom/alipay/android/app/util/FileFetch;

    invoke-virtual {v1}, Ljava/io/ObjectInputStream;->readLong()J

    move-result-wide v4

    invoke-virtual {v0, v4, v5}, Lcom/alipay/android/app/util/FileFetch;->setFileEnd(J)V
    :try_end_2
    .catchall {:try_start_2 .. :try_end_2} :catchall_2
    .catch Ljava/lang/Exception; {:try_start_2 .. :try_end_2} :catch_8

    :try_start_3
    invoke-virtual {v3}, Ljava/io/FileInputStream;->close()V
    :try_end_3
    .catch Ljava/lang/Exception; {:try_start_3 .. :try_end_3} :catch_5

    :goto_0
    :try_start_4
    invoke-virtual {v1}, Ljava/io/ObjectInputStream;->close()V
    :try_end_4
    .catch Ljava/lang/Exception; {:try_start_4 .. :try_end_4} :catch_6

    :goto_1
    return-void

    :catch_0
    move-exception v0

    move-object v1, v2

    :goto_2
    :try_start_5
    invoke-virtual {v0}, Ljava/lang/Exception;->printStackTrace()V
    :try_end_5
    .catchall {:try_start_5 .. :try_end_5} :catchall_3

    :try_start_6
    invoke-virtual {v2}, Ljava/io/FileInputStream;->close()V
    :try_end_6
    .catch Ljava/lang/Exception; {:try_start_6 .. :try_end_6} :catch_2

    :goto_3
    :try_start_7
    invoke-virtual {v1}, Ljava/io/ObjectInputStream;->close()V
    :try_end_7
    .catch Ljava/lang/Exception; {:try_start_7 .. :try_end_7} :catch_1

    goto :goto_1

    :catch_1
    move-exception v0

    goto :goto_1

    :catchall_0
    move-exception v0

    move-object v1, v2

    move-object v3, v2

    :goto_4
    :try_start_8
    invoke-virtual {v3}, Ljava/io/FileInputStream;->close()V
    :try_end_8
    .catch Ljava/lang/Exception; {:try_start_8 .. :try_end_8} :catch_3

    :goto_5
    :try_start_9
    invoke-virtual {v1}, Ljava/io/ObjectInputStream;->close()V
    :try_end_9
    .catch Ljava/lang/Exception; {:try_start_9 .. :try_end_9} :catch_4

    :goto_6
    throw v0

    :catch_2
    move-exception v0

    goto :goto_3

    :catch_3
    move-exception v2

    goto :goto_5

    :catch_4
    move-exception v1

    goto :goto_6

    :catch_5
    move-exception v0

    goto :goto_0

    :catch_6
    move-exception v0

    goto :goto_1

    :catchall_1
    move-exception v0

    move-object v1, v2

    goto :goto_4

    :catchall_2
    move-exception v0

    goto :goto_4

    :catchall_3
    move-exception v0

    move-object v3, v2

    goto :goto_4

    :catch_7
    move-exception v0

    move-object v1, v2

    move-object v2, v3

    goto :goto_2

    :catch_8
    move-exception v0

    move-object v2, v3

    goto :goto_2
.end method


# virtual methods
.method public final setFileUrl(Ljava/lang/String;)V
    .locals 0

    iput-object p1, p0, Lcom/alipay/android/app/util/FileDownloader;->fileUrl:Ljava/lang/String;

    return-void
.end method

.method public final setProgressOutput(Lcom/alipay/android/app/util/FileDownloader$IDownloadProgress;)V
    .locals 0

    if-eqz p1, :cond_0

    iput-object p1, p0, Lcom/alipay/android/app/util/FileDownloader;->progressOutput:Lcom/alipay/android/app/util/FileDownloader$IDownloadProgress;

    :cond_0
    return-void
.end method

.method public final setSavePath(Ljava/lang/String;)V
    .locals 2

    iput-object p1, p0, Lcom/alipay/android/app/util/FileDownloader;->savePath:Ljava/lang/String;

    new-instance v0, Ljava/lang/StringBuilder;

    invoke-static {p1}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v1

    invoke-direct {v0, v1}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    const-string v1, ".tmp"

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v0

    iput-object v0, p0, Lcom/alipay/android/app/util/FileDownloader;->tmpPath:Ljava/lang/String;

    return-void
.end method

.method public final setShowProgress(Z)V
    .locals 0

    iput-boolean p1, p0, Lcom/alipay/android/app/util/FileDownloader;->showProgress:Z

    return-void
.end method

.method protected final showProgress()Z
    .locals 1

    iget-boolean v0, p0, Lcom/alipay/android/app/util/FileDownloader;->showProgress:Z

    return v0
.end method

.method public start()V
    .locals 3

    new-instance v0, Lcom/alipay/android/app/util/FileDownloader$ProgressOutput;

    invoke-static {}, Landroid/os/Looper;->getMainLooper()Landroid/os/Looper;

    move-result-object v1

    const/4 v2, 0x0

    invoke-direct {v0, v1, p0, v2}, Lcom/alipay/android/app/util/FileDownloader$ProgressOutput;-><init>(Landroid/os/Looper;Lcom/alipay/android/app/util/FileDownloader;Lcom/alipay/android/app/util/FileDownloader$ProgressOutput;)V

    new-instance v1, Ljava/lang/Thread;

    new-instance v2, Lcom/alipay/android/app/util/FileDownloader$1;

    invoke-direct {v2, p0, v0}, Lcom/alipay/android/app/util/FileDownloader$1;-><init>(Lcom/alipay/android/app/util/FileDownloader;Lcom/alipay/android/app/util/FileDownloader$ProgressOutput;)V

    invoke-direct {v1, v2}, Ljava/lang/Thread;-><init>(Ljava/lang/Runnable;)V

    invoke-virtual {v1}, Ljava/lang/Thread;->start()V

    return-void
.end method

.method public stop()V
    .locals 1

    iget-object v0, p0, Lcom/alipay/android/app/util/FileDownloader;->fetch:Lcom/alipay/android/app/util/FileFetch;

    invoke-virtual {v0}, Lcom/alipay/android/app/util/FileFetch;->stop()V

    return-void
.end method

.method protected writeTempFile()V
    .locals 6

    const/4 v2, 0x0

    :try_start_0
    new-instance v3, Ljava/io/FileOutputStream;

    iget-object v0, p0, Lcom/alipay/android/app/util/FileDownloader;->tmpPath:Ljava/lang/String;

    invoke-direct {v3, v0}, Ljava/io/FileOutputStream;-><init>(Ljava/lang/String;)V
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    :try_start_1
    new-instance v1, Ljava/io/ObjectOutputStream;

    invoke-direct {v1, v3}, Ljava/io/ObjectOutputStream;-><init>(Ljava/io/OutputStream;)V
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_1
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_7

    :try_start_2
    iget-object v0, p0, Lcom/alipay/android/app/util/FileDownloader;->fetch:Lcom/alipay/android/app/util/FileFetch;

    invoke-virtual {v0}, Lcom/alipay/android/app/util/FileFetch;->getFileStart()J

    move-result-wide v4

    invoke-virtual {v1, v4, v5}, Ljava/io/ObjectOutputStream;->writeLong(J)V

    iget-object v0, p0, Lcom/alipay/android/app/util/FileDownloader;->fetch:Lcom/alipay/android/app/util/FileFetch;

    invoke-virtual {v0}, Lcom/alipay/android/app/util/FileFetch;->getFileEnd()J

    move-result-wide v4

    invoke-virtual {v1, v4, v5}, Ljava/io/ObjectOutputStream;->writeLong(J)V

    invoke-virtual {v1}, Ljava/io/ObjectOutputStream;->flush()V
    :try_end_2
    .catchall {:try_start_2 .. :try_end_2} :catchall_2
    .catch Ljava/lang/Exception; {:try_start_2 .. :try_end_2} :catch_8

    :try_start_3
    invoke-virtual {v3}, Ljava/io/FileOutputStream;->close()V
    :try_end_3
    .catch Ljava/lang/Exception; {:try_start_3 .. :try_end_3} :catch_5

    :goto_0
    :try_start_4
    invoke-virtual {v1}, Ljava/io/ObjectOutputStream;->close()V
    :try_end_4
    .catch Ljava/lang/Exception; {:try_start_4 .. :try_end_4} :catch_6

    :goto_1
    return-void

    :catch_0
    move-exception v0

    move-object v1, v2

    :goto_2
    :try_start_5
    invoke-virtual {v0}, Ljava/lang/Exception;->printStackTrace()V
    :try_end_5
    .catchall {:try_start_5 .. :try_end_5} :catchall_3

    :try_start_6
    invoke-virtual {v2}, Ljava/io/FileOutputStream;->close()V
    :try_end_6
    .catch Ljava/lang/Exception; {:try_start_6 .. :try_end_6} :catch_2

    :goto_3
    :try_start_7
    invoke-virtual {v1}, Ljava/io/ObjectOutputStream;->close()V
    :try_end_7
    .catch Ljava/lang/Exception; {:try_start_7 .. :try_end_7} :catch_1

    goto :goto_1

    :catch_1
    move-exception v0

    goto :goto_1

    :catchall_0
    move-exception v0

    move-object v1, v2

    move-object v3, v2

    :goto_4
    :try_start_8
    invoke-virtual {v3}, Ljava/io/FileOutputStream;->close()V
    :try_end_8
    .catch Ljava/lang/Exception; {:try_start_8 .. :try_end_8} :catch_3

    :goto_5
    :try_start_9
    invoke-virtual {v1}, Ljava/io/ObjectOutputStream;->close()V
    :try_end_9
    .catch Ljava/lang/Exception; {:try_start_9 .. :try_end_9} :catch_4

    :goto_6
    throw v0

    :catch_2
    move-exception v0

    goto :goto_3

    :catch_3
    move-exception v2

    goto :goto_5

    :catch_4
    move-exception v1

    goto :goto_6

    :catch_5
    move-exception v0

    goto :goto_0

    :catch_6
    move-exception v0

    goto :goto_1

    :catchall_1
    move-exception v0

    move-object v1, v2

    goto :goto_4

    :catchall_2
    move-exception v0

    goto :goto_4

    :catchall_3
    move-exception v0

    move-object v3, v2

    goto :goto_4

    :catch_7
    move-exception v0

    move-object v1, v2

    move-object v2, v3

    goto :goto_2

    :catch_8
    move-exception v0

    move-object v2, v3

    goto :goto_2
.end method
